package springdao.model;

import java.io.Serializable;
import javax.jdo.annotations.Column;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

/**
 *
 * @author Kent Yeh
 */
@PersistenceCapable(objectIdClass = UserStorePK.class, detachable = "true", table = "userstore")
public class UserStore implements Serializable {

    private static final long serialVersionUID = -5224533020424369470L;
    @PrimaryKey
    @Column(jdbcType = "BIGINT", name = "id")
    @Persistent(defaultFetchGroup = "true")
    private Member owner;
    @PrimaryKey
    @Column(jdbcType = "BIGINT", name = "sid")
    @Persistent(defaultFetchGroup = "true")
    private Storage storage;
    @PrimaryKey
    @Column(jdbcType = "VARCHAR", length = 100)
    private String goods;

    public UserStore() {
    }

    public String getGoods() {
        return goods;
    }

    public void setGoods(String goods) {
        this.goods = goods;
    }

    public Member getOwner() {
        return owner;
    }

    public void setOwner(Member owner) {
        this.owner = owner;
    }

    public Storage getStorage() {
        return storage;
    }

    public void setStorage(Storage storage) {
        this.storage = storage;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final UserStore other = (UserStore) obj;
        if (this.owner != other.owner && (this.owner == null || !this.owner.equals(other.owner))) {
            return false;
        }
        if (this.storage != other.storage && (this.storage == null || !this.storage.equals(other.storage))) {
            return false;
        }
        if ((this.goods == null) ? (other.goods != null) : !this.goods.equals(other.goods)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 19 * hash + (this.owner != null ? this.owner.hashCode() : 0);
        hash = 19 * hash + (this.storage != null ? this.storage.hashCode() : 0);
        hash = 19 * hash + (this.goods != null ? this.goods.hashCode() : 0);
        return hash;
    }

    @Override
    public String toString() {
        return String.format("%s's %s @ %s", owner.getName(), getGoods(), getStorage().getLocation());
    }
}
